<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Controller_cuspo
 *
 * @author andrea
 */
class Controller_cuspo {

  /**
   * Esegue l'operazione passata per parametro
   * @param string $operation 
   */
  public function executeOperation($operation) {
    /* @var $CCustompost CCustomposts_cuspo */
    $CCustompost = USingleton_cuspo::getInstances("CCustomposts_cuspo");
    /*@var $CFacebook CFacebook_cuspo*/
    $CFacebook = USingleton_cuspo::getInstances("CFacebook_cuspo");
    /*@var $CSlider CSlider_cuspo*/
    $CSlider = USingleton_cuspo::getInstances("CSlider_cuspo");
    /* @var $view View_cuspo */
    $view = USingleton_cuspo::getInstances("View_cuspo");
    
    if (preg_match("/cuspo\_add\_/", $operation) && !preg_match("/facebook/",$operation) && !preg_match("/slider/",$operation)) {
      $name = str_replace("cuspo_add_", "", $operation);
      $CCustompost->addPost($name);
    }
    if (preg_match("/cuspo\_update\_/", $operation)&& !preg_match("/facebook/",$operation)) {
      $name = str_replace("cuspo_update_", "", $operation);
      $CCustompost->updatePost($name);
    }
    if (preg_match("/cuspo\_update\_facebook/", $operation)) {
      $CFacebook->updateFacebook();
    }
    if (preg_match("/cuspo\_add\_facebook/", $operation)) {
      $CFacebook->addFacebook();
    }
    if (preg_match("/cuspo\_add\_slider/", $operation)) {
      $CSlider->addSlider();
    }
    if ($operation == "delete_post") {
      $post_id = $view->getRequest("post_id_del");
      $name = $view->getRequest("name");
      $CCustompost->deletePost($post_id, $name);
    }
    if ($operation == "get_edit_form") {
      $post_id = $view->getRequest("post_id");
      $name = $view->getRequest("name");
      $CCustompost->getEditPostForm($name, $post_id);
    }
  }

}

?>
